package com.quwan.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quwan.entity.TSpreadProfitList;
import com.quwan.entity.TSpreadSetting;
import com.quwan.manager.service.SpreadSettingService;
import com.quwan.mapper.TSpreadProfitListMapper;
import com.quwan.mapper.TSpreadSettingMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author quan
 * @date 2022-05-11 10:37
 */
@Service
@RequiredArgsConstructor
public class SpreadSettingServiceImpl implements SpreadSettingService {
    private final TSpreadSettingMapper settingMapper;
    private final TSpreadProfitListMapper profitListMapper;

    @Override
    public List<TSpreadSetting> getSpreadSettingList() {
        return settingMapper.selectPage(new Page<>(1, 10), new LambdaQueryWrapper<TSpreadSetting>().orderByAsc(TSpreadSetting::getScale)).getRecords();
    }

    @Override
    public boolean addSetting(TSpreadSetting params) {
        return settingMapper.insert(params) == 1;
    }

    @Override
    public boolean delSetting(String id) {
        return settingMapper.deleteById(id) == 1;
    }

    @Override
    public List<TSpreadProfitList> getProfitList() {
        return profitListMapper.selectPage(new Page<>(1, 10), new LambdaQueryWrapper<TSpreadProfitList>().orderByAsc(TSpreadProfitList::getMoney)).getRecords();
    }

    @Override
    public boolean delProfitList(String id) {
        return profitListMapper.deleteById(id) == 1;
    }
    @Override
    public boolean addProfitList(TSpreadProfitList params) {
        return profitListMapper.insert(params) == 1;
    }
}
